package logic

import (
	"context"
	"shuqinovelrpc/model/mysql"

	"shuqinovelrpc/shuqinovelrpc/internal/svc"
	"shuqinovelrpc/shuqinovelrpc/shuqinovelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoryLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoryLogic {
	return &StoryLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StoryLogic) Story(in *shuqinovelrpc.StoryRequest) (*shuqinovelrpc.StoryResponse, error) {
	// todo: add your logic here and delete this line
	story := mysql.Story{
		Name:   in.Name,
		Author: in.Author,
	}
	err := story.StoryAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &shuqinovelrpc.StoryResponse{
		StoryId: int64(story.ID),
	}, nil
}
